package com.roamer.audition.web.export;

import com.roamer.audition.common.request.CompanyPageQuery;
import com.roamer.audition.common.response.CompanyVO;
import com.roamer.audition.common.service.CompanyService;

import java.util.List;
import java.util.TimeZone;
import java.util.concurrent.Callable;

/**
 * SQL查询任务
 *
 * @author roamer
 * @version v1.0
 * @date 2019/10/13 15:53
 */
public class StatisticsTask implements Callable<List<CompanyVO>> {

    private final CompanyService companyService;
    private final int page;
    private final Long beginTime;
    private final Long endTime;

    public StatisticsTask(CompanyService companyService, int page, Long beginTime, Long endTime) {
        this.companyService = companyService;
        this.page = page;
        this.beginTime = beginTime;
        this.endTime = endTime;
    }

    @Override
    public List<CompanyVO> call() throws Exception {
        CompanyPageQuery pageQuery = new CompanyPageQuery();
        pageQuery.setPage(page);
        pageQuery.setSize(CompanyExcelService.BATCH_AMOUNT);
        // 当天零点零分零秒的毫秒数
        long zero = beginTime / (1000 * 3600 * 24) * (1000 * 3600 * 24) - TimeZone.getDefault().getRawOffset();
        // 23点59分59秒的毫秒数
        long twelve = zero + 24 * 60 * 60 * 1000 - 1;
        return companyService.getCompanyPage(pageQuery).getContent();
    }
}
